// SharksView.h : interface of the CSharksView class
//


#pragma once

#include "OpenGLView.h"
#include "shark.h"
#include "cTimer.h"
#include "font.h"

#include "BezierCamera.h"	// includes also camera.h

class CSharksDoc;

class CSharksView : public COpenGLView
{
protected: // create from serialization only
	CSharksView();
	DECLARE_DYNCREATE(CSharksView)

// Attributes
public:
	CSharksDoc* GetDocument() const;

// Operations
public:

// Overrides
	public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:

// Implementation
public:
	virtual ~CSharksView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	DECLARE_MESSAGE_MAP()

	

public:
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnDestroy();
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnSettingsProgramOptions();
	afx_msg void OnSetFocus(CWnd* pOldWnd);
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	afx_msg void OnNavigationGotonextshark();
	afx_msg void OnNavigationGotopreviousshark();

	//
	// OpenGL code here
	void RenderScene();
	void RenderBackgroundQuad();
	void LoadTextures();
	void RenderGround();
	void CalcAndSetFPS(double dt);
	
	void ShowCredits();
	void ShowCameraHelp();
	void ShowFishInfo(int fish_id);
	void GoToNextShark();
	void GoToPrevShark();
	void ReadIniFile();
	void LoadMainScript(const char* mainscript);
	void ResizeGLScene(GLsizei w,GLsizei h);
	void HideCursor();
	void RevealCursor();
	string BuildEditorParameters(/*const CString &scriptname*/);

	Fish* LoadFishFromString(vector<string> &inheritansePath, string &fishName);
	BOOL LoadScript();
	void OpenEditorToEditScript();
	void OpenEditorForNewScript();

	//
	// fps stuff
	struct tFPS
	{
		int m_frames;
		double fpsTime;		
	} m_fps;
	
	//
	// camera stuff
	enum enumCameraMode
	{	FIRSTPERSON_CAMERA, WAYPOINT_CAMERA, SHARKEYE_CAMERA };
	Camera	*m_pcamera;
	BezierCamera *m_pwaypointCam;
	enumCameraMode m_cameraMode;
	float m_waypointCamZoom;
	void ToggleCameraMode();
	void SetCameraMode(enumCameraMode mode);

	FishManager* m_pFishManager;
	Timer	m_timer;
	GLFont* pfont;
	GLuint	caustTexures[32];		// the caustics texture array
	GLuint	groundTexture;
	int		m_curCaustic;			// which is the current caustic blended in the scene?
	double  m_changeCaustInterv;	// time passed between caustic changes
	double	m_causticTimeElapsed;	// time since last caustic change
	float	m_caustiScale;
	BOOL	m_bPaused;				// is the game paused
	BOOL	m_bWasPaused;			// keep pause state for later restoration		
	BOOL	m_bHasFocus;
	CString m_windowTitle;
	Frustum *m_pfrustum;			// frustum for culling

	// just testing objects for ray tracing-----
	BoundingBox m_box;
	Ray m_ray;
	BoundingSphere m_sphere;
	void TestRay(void);
	//--------------------------

	GLfloat	m_terrainSize;			// size of the terrain
	int		m_terrainTile;			// how many rows and columns of the terrain
									// TODO: make better terrain
	int		m_iCameraFish;			// index of the shark the camera is looking at
	Fish*	m_pCameraFish;
	BOOL	m_bCameraFollowsFish;	// if true, then camera follows m_iCameraFish

	BOOL	m_bIniFileExists;
	string	m_strCameraMode;		// for showing in the screen the current camera mode

	//
	// view parameters
	BOOL m_bShowWireframe;
	BOOL m_bShowSharkShadows;
	BOOL m_bShowCaustics;			// enable or not multitexturing for caustics	
	BOOL m_bShowBoundingSpheres;
	BOOL m_bEnableCulling;
	BOOL m_bShowPaths;				// show shark paths as bezier lines
	BOOL m_bShowCredits;
	BOOL m_bShowHelp;

	int m_width,m_height;

	GLfloat	m_lightpos[4];
	GLfloat	m_matamb[4];
	GLfloat	m_matdiff[4];
	GLfloat	m_matspec[4];
	GLfloat m_clrColor[4];
	GLfloat m_sharkShadowColor[4];

	GLdouble m_fovy;				// the y angle of the field of view (used in
									// gluPerspective)

	float rotx,roty;
	float zoom;
	float m_planeHeight;
	unsigned int m_iCursorShow;				// if zero, cursor is not displayed
	
	std::string mStrMainScriptFile;	// the main script filename that is currently open
	
	
	
	afx_msg void OnNavigationGotocenterofterrain();
	afx_msg void OnNavigationFollowpreviousshark();
	afx_msg void OnNavigationFollownextshark();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnEditScripteditor();
	afx_msg void OnFileOpenscript();
	afx_msg void OnEditorNewscript();
	afx_msg void OnEditReloadscript();
};

#ifndef _DEBUG  // debug version in SharksView.cpp
inline CSharksDoc* CSharksView::GetDocument() const
   { return reinterpret_cast<CSharksDoc*>(m_pDocument); }
#endif

